﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DevExpress.XtraGrid.Views.Grid;
using QuanLyKho.PhongThanhPham;

namespace QuanLyKho.BanHang
{
    public partial class DSChiaSPTrongCH : UserControl
    {
        public DSChiaSPTrongCH()
        {
            InitializeComponent();
            LoadData();
            SetPropertiesGrid();
        }

        public void LoadData()
        {
            var table = DataAll.SelectAll("SanPhamTrongCuaHang LEFT JOIN DkChung_CuaHang ON [SanPhamTrongCuaHang].TenCuaHang = DkChung_CuaHang.TenCuaHang",
                "[SanPhamTrongCuaHang].ID,DkChung_CuaHang.TenCuaHang,DkChung_CuaHang.DiaChi,DkChung_CuaHang.SoDienThoai,SanPhamTrongCuaHang.*", "");
            gridCuaHang.DataSource = table;
            SetPropertiesGrid();
        }

        public void SetPropertiesGrid()
        {
            //gvChiaHang.BestFitColumns();
            gvCuaHang.OptionsBehavior.Editable = false;
            gvCuaHang.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
            gvCuaHang.OptionsSelection.EnableAppearanceFocusedCell = false;
            gvCuaHang.OptionsSelection.MultiSelect = true;
            gvCuaHang.OptionsView.ShowGroupPanel = false;
            gvCuaHang.OptionsView.ColumnAutoWidth = true;
            gvCuaHang.OptionsView.ShowFooter = true;
            gvCuaHang.OptionsFind.AlwaysVisible = true;
            gvCuaHang.Columns["ID"].Visible = false;
        }

        private void bntThemMoi_Click(object sender, EventArgs e)
        {
            var chiasp = new ChiaSPChoCuaHang();
            chiasp.ShowDialog();
            LoadData();
        }

        private void gvCuaHang_DoubleClick(object sender, EventArgs e)
        {
            if (gvCuaHang.FocusedRowHandle >= 0)
            {
                ChiaSPChoCuaHang.SoChungTu = gvCuaHang.GetDataRow(gvCuaHang.FocusedRowHandle)["SoChungTu"].ToString();
                var themsp = new ChiaSPChoCuaHang();
                themsp.ShowDialog();
                LoadData();
                ChiaSPChoCuaHang.SoChungTu = "0";
            }
        }
    }
}
